package com.sunny.ynhz.utils;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;

/**
 * Created by OldWang on 2016/4/1 0001.
 */
public class MyPDialog {

    private Context mContext;
    private ProgressDialog dialog;
    public MyPDialog(Context context) {
        mContext = context;
        dialog = new ProgressDialog(context,ProgressDialog.THEME_HOLO_LIGHT);
    }

    public void showDialog(String message) {
        dialog.setMessage(message);
        dialog.setCanceledOnTouchOutside(false);
        dialog.setCancelable(true);
        dialog.show();
        DisplayMetrics dm = new DisplayMetrics();
        ((Activity)mContext).getWindowManager().getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels;
        Window window = dialog.getWindow();
        WindowManager.LayoutParams params = window.getAttributes();
        params.alpha = 0.8f;
        params.width = (int) (width*0.8);
        window.setAttributes(params);
    }

    public void closeDialog() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }


}
